home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0016_WILDCRD1.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  65 lines

  1. Program wild_card;
  2.  
  3. Var
  4.    check:Boolean;
  5.  
  6. Function Wild(flname,card:String):Boolean;
  7. {Returns True if the wildcard description in 'card' matches 'flname'
  8. according to Dos wildcard principles.  The 'card' String MUST have a period!
  9. Example: Wild('test.tat','t*.t?t' returns True}
  10.  
  11. Var
  12.    name,temp:String[12];
  13.    c:Char;
  14.    p,i,n,l:Byte;
  15.    period:Boolean;
  16.  
  17. begin
  18.     wild:=True;
  19.     {test For special Case first}
  20.     if flname='*.*' then Exit;
  21.     wild:=False;
  22.     p:=pos('.',card);
  23.     i:=pos('.',flname);
  24.     if p > 0 then period:=True else Exit; {not a valid wildcard if no period}
  25.     N:=1;
  26.     Repeat
  27.        if card[n]='*' then n:=p-1 else
  28.         if (upCase(flname[n]) <> upCase(card[n])) then
  29.          if card[n]<>'?' then Exit;
  30.                 inc(n);
  31.     Until n>=p;
  32.     n:=p+1; {one position past the period of the wild card}
  33.     l:=length(flname);
  34.     inc(i); {one position past the period of the Filename}
  35.     Repeat
  36.     if n > length(card) then Exit;
  37.     c:=upCase(card[n]);
  38.          if c='*' then i:=l+1 {in order to end the loop}
  39.           else
  40.              if (upCase(flname[i]) = c) or (c = '?') then
  41.                 begin
  42.                 inc(n);
  43.                 inc(i);
  44.                 end
  45.              else Exit;
  46.     Until i > l;
  47.  
  48.     wild:=True;
  49.  
  50. end;
  51.  
  52. begin
  53.   check:=False;
  54.   check:=wild('TEST.Tat','T*.T?T'); {True}
  55.   Writeln(check);
  56.   check:=wild('TEST.Taq','T*.T?T');  {False}
  57.   Writeln(check);
  58.   check:=wild('12345678.pkt','*.pkt'); {True}
  59.   Writeln(check);
  60.   check:=wild('test.tat','T*.t?');  {False}
  61.   Writeln(check);
  62.   check:=wild('12345678.pkt','1234?678.*'); {True}
  63.   Writeln(check);
  64.  
  65. end.